package cn.org.zx.common.file;

import java.io.BufferedWriter;  
import java.io.File;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import java.io.OutputStreamWriter;  
import java.io.UnsupportedEncodingException;
import java.io.Writer;  
import java.util.ArrayList;  
import java.util.Date;
import java.util.HashMap;  
import java.util.List;  
import java.util.Map;  

import cn.org.zx.common.dao.DBAccess;
  
import freemarker.template.Configuration;  
import freemarker.template.Template;  
import freemarker.template.TemplateException;  

public class CreateToHtml {
	private Configuration configuration = null;  
    
    public CreateToHtml(){  
        configuration = new Configuration();  
        configuration.setDefaultEncoding("UTF-8");  
    }  
      
    public boolean createWord(String strFileName,String strJFID,String strDocFileName){  
        Map<String,Object> dataMap = new HashMap<String,Object>();
        boolean breturn = true;
        getData(dataMap,strJFID);  
        configuration.setClassForTemplateLoading(this.getClass(), "/cn/org/shbxfinance/templet/");  
        Template t = null;  
        try {  
            t = configuration.getTemplate(strFileName); 				
        } catch (IOException e) { 
        	breturn = false;
            e.printStackTrace();  
        }
        
        File outFile = new File(strDocFileName);  
        Writer out = null;  
        try {  
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
        } catch (FileNotFoundException e1) {        	
            e1.printStackTrace(); 
            return false;
        } catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return false;
		}  
           
        try {  
            t.process(dataMap, out);
            outFile.delete();
            out.close();
        } catch (TemplateException e) {  
            e.printStackTrace();
            return false;
        } catch (IOException e) {  
            e.printStackTrace(); 
            return false;
        } 
        
        return true;
    }  
  
    private void getData(Map<String, Object> dataMap,String strBFID) {    	
    	String strSql = "";
    	strSql = "select * from tb_bzht_fr where bfid="+strBFID;
    	Map map = DBAccess.queryOneRow(strSql);
    	
        //dataMap.put("bf001",StringUtils.toString(map.get("bfhetongbianhe")));				//合同编号
        
        
    }  
}
